package org.szy.plugin.sys.pojo;

import cn.hutool.core.convert.Convert;
import org.szy.core.common.entity.TreeSelect;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 主系统树结构实体类
 *
 * @author 孙志阳
 * @date 2021-11-01
 * @since 2.0.0
 **/
public class SysMenuTreeOption extends TreeSelect {

    private String application;
    private Integer type;

    public SysMenuTreeOption(SysMenuTree entity) {
        this.setId(Convert.toStr(entity.getId()));
        this.setSpareId(entity.getPid() + "");
        this.setLabel(entity.getName());
        this.setValue(this.getId());
        this.setApplication(entity.getApplication());
        this.setType(entity.getType());
        if (entity.getChildren() == null || entity.getChildren().isEmpty()) {
            this.setChildren(null);
        } else {
            this.setChildren(entity.getChildren().stream().map(SysMenuTreeOption::new).collect(Collectors.toList()));
        }
    }

    public static List<SysMenuTreeOption> buildTreeOption(List<SysMenuTree> trees) {
        return trees.stream().map(SysMenuTreeOption::new).collect(Collectors.toList());
    }

    public String getApplication() {
        return application;
    }

    public void setApplication(String application) {
        this.application = application;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }
}
